#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ls (p<<1)
#define rs ((p<<1)+1)
#define mid ((c[p].l+c[p].r)>>1)
const int N = 5e5+10;
int n,m,a[N],f[N],id[N],id1[N],x,y,cnt,cnt1,mx[N],ans,bj,mi;
struct w
{
	int l,z,z1;
}q[N<<1];
struct w1
{
	int p,l,r,mi;
}c[N<<2];
inline bool cmp(w x,w y){return x.l<y.l;}
void build(int p,int l,int r)
{
	c[p].l = l,c[p].r = r,c[p].mi = 1e15;
	if(l == r) return;
	build(ls,l,mid),build(rs,mid+1,r);
}
void change(int p,int l,int k)
{
	if(c[p].l == l && c[p].r == l)
	{
		c[p].mi = k;
		return;
	}
	if(l <= mid) change(ls,l,k);
	else change(rs,l,k);
	c[p].mi = min(c[ls].mi,c[rs].mi);
}
void query(int p,int l,int r)
{
	if(l <= c[p].l && c[p].r <= r)
	{
		mi = min(mi,c[p].mi);
		return;
	}
	if(l <= mid) query(ls,l,r);
	if(mid < r) query(rs,l,r);
}
signed main()
{
	freopen("gonna.in","r",stdin);
	freopen("gonna.out","w",stdout);
	scanf("%lld",&n);
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	scanf("%lld",&m);
	for(int i = 1;i <= m;i++) scanf("%lld%lld",&x,&y),q[++cnt].l = x,q[cnt].z = 1,q[++cnt].l = y+1,q[cnt].z = -1,q[cnt].z1 = x;
	sort(q+1,q+1+cnt,cmp);
	cnt1 = 1;
	for(int i = 1;i <= n;i++)
	{
		mx[i] = mx[i-1];
		while(cnt1 <= cnt && q[cnt1].l == i) 
		{
			if(q[cnt1].z == -1) mx[i] = max(mx[i],q[cnt1].z1);
			else bj++;
			cnt1++;
		}
		id[i] = bj;
	}
	ans = 1e15;
	for(int i = 1;i <= n;i++) f[i] = 1e15;
	build(1,1,n);
	for(int i = 1;i <= n;i++)
	{
		if(mx[i] == 0) mi = 0;
		else mi = 1e15;
		query(1,max(1ll,mx[i]),i-1);
		f[i] = mi+a[i];
		change(1,i,f[i]);
	}
	for(int i = 1;i <= n;i++)
		if(id[i] == m) 
			ans = min(ans,f[i]);
	printf("%lld",ans);
	return 0;
}


